﻿Public Class Comercial : Inherits PictureBox
    Public pos As Integer
    Dim imagen As Integer
    Public Sub New()
        Dim mal As Integer = 0
        Me.Width = 33
        Me.Height = 50
        Dim bien As Integer = 0
        Do 'Bucle algo cutre para que los comerciales no salgan montados
            mal = 0
            bien += 1
            pos = random.Next(5) + 1
            Me.Top = pos * 50
            Me.Left = 500 + random.Next(500)
            For Each Comercial In Main.juego.comerciales
                If Not Comercial.Equals(Me) Then
                    If colision(Comercial.left, Comercial.top, Comercial.width, Comercial.height) Then
                        mal = 1
                    End If
                End If
            Next
            If bien = 10 Then
                mal = 0
            End If
        Loop While mal = 1
        Me.Image = My.Resources.Comercial1
        imagen = random.Next(4)
    End Sub
    Public Sub mover()
        Me.Left -= Main.juego.pj.vx
        If Me.Left < -50 Then
            Main.juego.comerciales.Remove(Me)
            Main.juego.Controls.Remove(Me)
        End If
    End Sub
    Public Function colision(ByVal x As Integer, ByVal y As Integer, ByVal w As Integer, ByVal h As Integer) As Boolean
        Return Me.Top + Me.Height > y And Me.Top < y + h And Me.Left + Me.Width > x And Me.Left < x + w
    End Function
    Public Sub animar()
        Static siguientemov As Integer = 10
        siguientemov -= 1
        If siguientemov = 0 Then
            siguientemov = 10
            If imagen = 0 Then
                imagen = 1
                Image = My.Resources.Comercial2
            ElseIf imagen = 1 Then
                imagen = 2
                Image = My.Resources.Comercial3
            ElseIf imagen = 2 Then
                imagen = 3
                Image = My.Resources.Comercial2
            ElseIf imagen = 3 Then
                imagen = 0
                Image = My.Resources.Comercial1
            End If
        End If
    End Sub
End Class
